package idiolect.webstorage;

import javax.swing.table.DefaultTableModel;
import java.util.List;

class TopicInfoTableModel extends DefaultTableModel {
    static final String[] COLUMNS = {"Name", "Size", "Revision", "Date", "Author"};
    static final String[] WIDTHS = {"Name", "Size", "Revision", "Date", "Author"};
    private final List<TopicInfo> data;

    public TopicInfoTableModel(List<TopicInfo> data) {
        this.data = data;
        Object[][] dataVector = new Object[data.size()][6];
        for (int i = 0; i < data.size(); i++) {
            TopicInfo info = data.get(i);
            dataVector[i] = new Object[]{info.name, info.size, info.revision, info.date, info.author};
        }
        setDataVector(dataVector, COLUMNS);
    }

    public TopicInfo getTopicInfo(int row) {
        if (row >= data.size() || row < 0)
            return null;
        return data.get(row);
    }

    public boolean isCellEditable(int row, int column) {
        return false;
    }
}
